home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7701 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.6 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Increasing stack size - HELP!
  5. Date: 25 Feb 1996 10:50:21 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4gpetd$qu2@news1.usa.pipeline.com>
  8. References: <NEWTNews.825237165.25683.koz@dialup.netvision.net.il>
  9. NNTP-Posting-Host: pipe14.h1.usa.pipeline.com
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete)
  13. X-Newsreader: Pipeline USA v3.3.0
  14.  
  15. On Feb 25, 1996 00:23:09 in article <Re: Increasing stack size - HELP!>,
  16. 'koz@netvision.net.il' wrote: 
  17.  
  18. >> From: Francesco Fantauzzi <mapgfgf@brunel.ac.uk> 
  19. >> Newsgroups: comp.lang.c++,comp.lang.c 
  20. >> Subject: Increasing stack size - HELP! 
  21. >> Date: 20 Feb 1996 11:58:09 GMT 
  22. >>  
  23. >> Hi All! 
  24. >>  
  25. >> I'm using Borland C++ 4.0. I'm stuck 'cause, when I run my program, it  
  26. >> stops with a run-time error: "STACK OVERFLOW!".  
  27. >>  
  28. >> I checked the stack size (with stackavail()) and it's actually too
  29. small.  
  30. >> How can I tell the compiler that I would like a larger stack, overriding
  31.  
  32. >> the default size? I'm sure there's a way: I did it years ago, but have  
  33. >> forgotten it.  
  34. >>  
  35. >> BTW, I'm writing a plain MS-DOS application with the compact memory  
  36. >> model. 
  37. >>  
  38. >> Thanks for any help. 
  39. >>  
  40. >> Francesco G. Fantauzzi 
  41. >>  
  42. >>  
  43. >Just use the next line : 
  44. >extern unsigned _stklen = NewStackSize; 
  45. >(It should be writen in the global section of the program, not in  
  46. >ANY procedure). 
  47. > ..[ portions trimmed ] 
  48.  
  49. Although the above may work in some cases, and occasionally may 
  50. even be the best solution, generally it's not a good idea.  Running 
  51. out of stack space is often caused by poor programming practices,  
  52. usually by those with little experience in software development. 
  53.  
  54. To the original poster, I'd like to suggest that you examine your 
  55. program to see where you are using up the stack unnecessarily 
  56. and use allocation off the global heap instead.  Examples of 
  57. such "fixups" are: 
  58.  
  59. int Boo () 
  60.  { 
  61.    int foo[500]; 
  62.  
  63. Here you are grabbing off 1000 or 2000 bytes off the stack, 
  64. depending on the size of int on your machine.  Either move 
  65. the declaration outside the function into global space (not my 
  66. recommendation), or better yet, use dynamic memory: 
  67.  
  68. int Boo () 
  69.  { 
  70.     int * foo = new int[500]; 
  71.  
  72. (Your post was to both comp.lang.c and c++.  If you're a  
  73. C programmer, use malloc instead of new). 
  74.   
  75. If the poster's only interest is in getting the current program to 
  76. run so that it can earn its writer a grade, then I've wasted my 
  77. time -- and bandwith -- :-) 
  78.  
  79. -- 
  80. Pete Grant 
  81. Kalevi, Inc. 
  82. Software Engineering & development
  83.